$(function(){
	var chooseAll = $('.choose-all');//全选按钮
	var inverseAll = $('.inverse-all');//反选按钮
	var oTable = $('.table');//表格
	var addDeptName = $('#add-dept-name');//添加部门名字input框
	var addDeptBtn = $('.add-dept-btn');//弹框里的添加部门按钮
	var addDeptNo = $('#add-dept-no');  //添加部门里的输入框
	var addDeptTel = $('#add-dept-tel');
	var addDeptAdr = $('#add-dept-adr');
	var addDeptPeo = $('#add-dept-peo');
	
	var mdfDeptName = $('#mdf-dept-name');//修改部门信息里的输入框
	var mdfDeptNo = $('#mdf-dept-no');
	var mdfDeptTel = $('#mdf-dept-tel');
	var mdfDeptMins = $('#mdf-dept-mins');
	var mdfDeptVice = $('#mdf-dept-vice');
	var mdfDeptAdr = $('#mdf-dept-adr');
	var mdfDeptPeo = $('#mdf-dept-peo');
	
	var addYgName = $('#add-yg-name');//添加成员弹框里的输入框
	var addYgDept = $('#add-yg-dept');
	var addYgPos = $('#add-yg-pos');
	var addYgTel = $('#add-yg-tel');
	var addYgAge = $('#add-yg-age');
	
	var deleteDept = $('.delete');//删除单个部门按钮
	var deleteAllBtn = $('.delete-all');//删除多个部门按钮
	var info = $('.modify-list>li>input[type = text]')//信息修改弹框的输入框
	var arr = [];
	var searchIpt = $('.glyphicon-search');//搜索框
	
	var firLoadPage = 1;
	var oNext = $('.next');
	var oPre = $('.pre');
	
	var deptReg = /^[\u4e00-\u9fa5]{2,5}$/;
	var nameReg = /^[\u4e00-\u9fa5]{2,5}$/;
	var telReg = /^1[3|4|5|7|8|9]\d{9}$/;
	var officeReg = /^[a-z]\d{3}$/;
	var pwdReg = /^[0-9A-Za-z]{6,20}$/;
	var ageReg = /^(?:[1-9][0-9]?|1[01][0-9]|120)$/ //1-120
	var userReg = /^[0-9A-Za-z]{6,20}$/;
	
	
	var idArr = [
		[
			{deptNo:1,dept:'后勤部',office:'w301',tel:13568978998,minister:'',Vice:'',number:''},
			{deptNo:22,dept:'教务部',office:'d203',tel:15568978998,minister:'',Vice:'',number:''},
			{deptNo:3,dept:'行政部',office:'w401',tel:17568978998,minister:'',Vice:'',number:''},
			{deptNo:4,dept:'宣传部',office:'b541',tel:19568978998,minister:'',Vice:'',number:''},
			{deptNo:5,dept:'保卫部',office:'a341',tel:18568978998,minister:'',Vice:'',number:''},
			{deptNo:6,dept:'保育部',office:'e321',tel:13562222998,minister:'',Vice:'',number:''},
			{deptNo:7,dept:'伙食部',office:'e321',tel:13533338998,minister:'',Vice:'',number:''}
		],
		[
			{dept:'后勤部',name:'张三',position:'部长',tel:15789932141,age:41},
			{dept:'后勤部',name:'张上',position:'副部长',tel:13744932141,age:51},
			{dept:'后勤部',name:'白居易',position:'保洁员',tel:15755521411,age:44},
			{dept:'后勤部',name:'王者荣',position:'保洁员',tel:18744432141,age:29},
			{dept:'后勤部',name:'安妮',position:'保洁员',tel:15763258741,age:51},
			{dept:'后勤部',name:'波塞冬',position:'保洁员',tel:15725808741,age:41},
			{dept:'后勤部',name:'可汗',position:'维修工',tel:15763258741,age:43},
			{dept:'后勤部',name:'小豪',position:'司机',tel:15763345741,age:42},
			
			{dept:'行政部',name:'王五',position:'部长',tel:17885252423,age:41},
			{dept:'行政部',name:'张伟',position:'副部长',tel:13258963578,age:51},
			{dept:'行政部',name:'张家辉',position:'员工',tel:13232963578,age:33},
		
			{dept:'保卫部',name:'肖扬',position:'部长',tel:15789934141,age:43},
			{dept:'保卫部',name:'张非',position:'副部长',tel:13744945141,age:31},
			{dept:'保卫部',name:'李白',position:'巡逻',tel:17789123141,age:32},
			{dept:'保卫部',name:'杜甫',position:'保安',tel:15741345714,age:21},

			{dept:'宣传部',name:'阴阳师',position:'部长',tel:15723234141,age:47},
			{dept:'宣传部',name:'洋洋',position:'副部长',tel:15678945141,age:21},
			{dept:'宣传部',name:'白居易',position:'会计',tel:13456794514,age:34},

			{dept:'保育部',name:'芳芳',position:'部长',tel:15725554141,age:37},
			{dept:'保育部',name:'菲菲',position:'副部长',tel:17858945141,age:23},
			{dept:'保育部',name:'咳咳',position:'保育员',tel:15558922141,age:21},
			{dept:'保育部',name:'嘎嘎嘎',position:'保育员',tel:13338945124,age:24},
			{dept:'保育部',name:'烦烦烦',position:'保育员',tel:15438945124,age:27},
			
			{dept:'伙食部',name:'李世民',position:'部长',tel:15725554142,age:37},
			{dept:'伙食部',name:'月娥',position:'副部长',tel:17858945143,age:23},
			{dept:'伙食部',name:'宙斯',position:'厨师',tel:15763251234,age:31},
			{dept:'伙食部',name:'美杜莎',position:'采购员',tel:13746325844,age:51},
		],
		[
			{name:'龙龙',tel:13578901001,isDuty:'yes',sex:'男',bthDay:'1982-01-23',age:25,Job:'L020030612',tcHcu:'无课',oTime:'2003-06-12',dept:'教务部',post:'校长',level:'高级教师',Growth_Archives:'这是一位充满青春热血的校长'},
			{name:'欣欣',tel:13578901002,isDuty:'yes',sex:'女',bthDay:'1990-06-13',age:25,Job:'Z020070414',tcHcu:'幼儿语文',oTime:'2007-04-14',dept:'教务部',post:'部长',level:'高级教师',Growth_Archives:'这是一位细心的老师'},
			{name:'泽泽',tel:13578901003,isDuty:'yes',sex:'男',bthDay:'1983-02-25',age:25,Job:'J020120512',tcHcu:'幼儿数学',oTime:'2012-05-12',dept:'教务部',post:'老师',level:'初级教师',Growth_Archives:'这是一位耐心的老师'},
			{name:'涵涵',tel:13578901004,isDuty:'yes',sex:'女',bthDay:'1995-04-14',age:25,Job:'H020070812',tcHcu:'幼儿故事',oTime:'2007-08-12',dept:'教务部',post:'老师',level:'初级教师',Growth_Archives:'这是一位好看的老师'},
			{name:'梅梅',tel:13578901005,isDuty:'yes',sex:'女',bthDay:'1987-04-05',age:25,Job:'M020121012',tcHcu:'幼儿美术',oTime:'2012-10-12',dept:'教务部',post:'老师',level:'中级教师',Growth_Archives:'这是一位漂亮的老师'},
			{name:'佳佳',tel:13578901021,isDuty:'yes',sex:'女',bthDay:'1992-05-15',age:25,Job:'J020041102',tcHcu:'幼儿品德',oTime:'2004-11-02',dept:'教务部',post:'副部长',level:'高级教师',Growth_Archives:'这是一位认真的老师'},
			{name:'强强',tel:13578901021,isDuty:'yes',sex:'男',bthDay:'1991-07-30',age:25,Job:'Q020051012',tcHcu:'幼儿英语',oTime:'2005-10-12',dept:'教务部',post:'老师',level:'初级教师',Growth_Archives:'这是一位帅气的老师'},
			{name:'薇薇',tel:13578901031,isDuty:'yes',sex:'女',bthDay:'1993-02-20',age:25,Job:'W020051112',tcHcu:'幼儿英语',oTime:'2005-11-12',dept:'教务部',post:'老师',level:'中级教师',Growth_Archives:'这是一位美丽的老师'},
			{name:'依依',tel:13578901041,isDuty:'yes',sex:'女',bthDay:'1990-05-30',age:25,Job:'W020070424',tcHcu:'幼儿数学',oTime:'2007-04-24',dept:'教务部',post:'老师',level:'初级教师',Growth_Archives:'这是一位用心的老师'},
			{name:'丽丽',tel:13578901051,isDuty:'yes',sex:'女',bthDay:'1992-07-30',age:25,Job:'W020120320',tcHcu:'幼儿早教',oTime:'2012-03-20',dept:'教务部',post:'老师',level:'高级教师',Growth_Archives:'这是一位用心的老师'},
			{name:'茜茜',tel:13578901231,isDuty:'no',sex:'女',bthDay:'1989-06-24',age:25,Job:'W020051112',tcHcu:'幼儿英语',oTime:'2005-11-12',dept:'教务部',post:'老师',level:'初级教师',Growth_Archives:'这是一位用心的老师'},
			{name:'旭旭',tel:13578901061,isDuty:'no',sex:'男',bthDay:'1988-05-27',age:25,Job:'W020121218',tcHcu:'幼儿体育',oTime:'2012-12-18',dept:'教务部',post:'老师',level:'中级教师',Growth_Archives:'这是一位用心的老师'},
			{name:'倩倩',tel:13578901071,isDuty:'no',sex:'女',bthDay:'1993-11-02',age:25,Job:'W020021004',tcHcu:'幼儿品德',oTime:'2002-10-04',dept:'教务部',post:'老师',level:'初级教师',Growth_Archives:'这是一位用心的老师'},
			{name:'静静',tel:13578901201,isDuty:'no',sex:'女',bthDay:'1995-04-20',age:25,Job:'W020070502',tcHcu:'幼儿故事',oTime:'2007-05-02',dept:'教务部',post:'老师',level:'初级教师',Growth_Archives:'这是一位用心的老师'},
			{name:'星星',tel:13578901301,isDuty:'no',sex:'女',bthDay:'1989-12-20',age:25,Job:'W020170210',tcHcu:'幼儿英语',oTime:'2017-02-10',dept:'教务部',post:'老师',level:'初级教师',Growth_Archives:'这是一位用心的老师'},
			{name:'维维',tel:13578901401,isDuty:'no',sex:'男',bthDay:'1996-05-28',age:25,Job:'W020040820',tcHcu:'幼儿数学',oTime:'2004-08-20',dept:'教务部',post:'老师',level:'高级教师',Growth_Archives:'这是一位用心的老师'},
			{name:'超超',tel:13578901501,isDuty:'no',sex:'女',bthDay:'1994-02-12',age:25,Job:'W020070112',tcHcu:'幼儿语文',oTime:'2007-01-12',dept:'教务部',post:'老师',level:'中级教师',Growth_Archives:'这是一位用心的老师'},
			{name:'成成',tel:13578901601,isDuty:'no',sex:'男',bthDay:'1995-06-10',age:25,Job:'W020050714',tcHcu:'幼儿品德',oTime:'2005-07-14',dept:'教务部',post:'老师',level:'初级教师',Growth_Archives:'这是一位用心的老师'},
			{name:'雪雪',tel:13578901701,isDuty:'no',sex:'女',bthDay:'1997-05-08',age:25,Job:'W020060923',tcHcu:'幼儿故事',oTime:'2006-09-23',dept:'教务部',post:'老师',level:'高级教师',Growth_Archives:'这是一位用心的老师'},
		]
		
	]
	var tableNameArr = ['部门管理','员工','teaInform'];
	/* 数据加载部分 */
	var arrYg = JSON.parse(localStorage.getItem('员工')) || [];
	var arrTeacher = JSON.parse(localStorage.getItem('teaInform')) || [];
	var json = JSON.parse(localStorage.getItem('部门管理')) || [];
	
	
	function render(){
		//showPage();
		ygData ();
		tec();
		var indexP = paging(firLoadPage);		
		if(indexP.length == 0){
			showPage()
			indexP = paging(parseInt($('.pagination-list:last-child').text()));	
		}
		console.log(indexP)
		$('.table-body').html('');
		for(var j=0;j<indexP.length;j++){
				
				$('<tr><td><input type="checkbox" class = "checkBtn"></td><td>'
				+(j+1)+'</td><td><span class="dept-name">'
				+indexP[j].dept+'</span></td><td>'
				+indexP[j].deptNo+'</td><td>'
				+indexP[j].number+'</td><td>'
				+indexP[j].office+'</td><td>'
				+indexP[j].tel+'</td><td>'
				+indexP[j].minister+'</td><td>'
				+indexP[j].Vice+'</td><td></td><td><span data-placement="top" data-toggle="modal" data-target="#myModal2" title="修改"><i class="fa fa-pencil-square-o modify" aria-hidden="true"></i></span><span data-placement="top" title="删除"><i class="fa fa-trash delete" data-toggle="modal" data-target="#myModal3" aria-hidden="true"></i></span></td>'
				+'<td><input type="text" class="remark"/></td></tr>').appendTo($('.table-body'));
			}
			
			localStorage.setItem('员工',JSON.stringify(arrYg));
			localStorage.setItem('部门管理',JSON.stringify(json));
			localStorage.setItem('teaInform',JSON.stringify(arrTeacher));
			
	}
	if(paging(firLoadPage)){
		render();
	}
	
	function setLocalStorage(arr){
		$.each(arr,function(i,n){
			localStorage.setItem(tableNameArr[i],JSON.stringify(n));
		})	
	};

setLocalStorage(idArr);

 function ygData (){
	 var a = 0;
	 var b = 0;
	 var c = 0;
	 var d = 0;
	 var e = 0;
	 var f = 0;
	 var g = 0;
	 $.each(json,function (index,element) {
			element.minister = '';
			element.Vice = '';
			element.number = ''
	 })
	 
 	$.each(arrYg,function(i,v){
 		if(v.dept == '后勤部'){
 			a++;
 		}else if(v.dept == '行政部'){
 			b++;
 		}else if(v.dept == '保卫部'){
 			c++;
 		}else if(v.dept == '宣传部'){
 			d++;
 		}else if(v.dept == '保育部'){
 			e++;
 		}else if(v.dept == '伙食部'){
 			f++;
 		}
		// else if(v.dept == '教务部'){
 		// 	g++;
 		// }
 		$.each(json,function(i1,v1){
 			if(v1.dept == v.dept && v.position == '部长'){
 				v1.minister = v.name;
 			}
 			
 			if(v.position == '副部长'&&v.dept == v1.dept){
 				v1.Vice = v.name;
	
 			}
 			switch(v1.dept){
 				case '后勤部':
 					v1.number = a ;
 					break;
 				case '行政部':
 					v1.number = b ;
 					break;
 				case '保卫部':
 					v1.number = c ;
 					break;
 				case '宣传部':
 					v1.number = d ;
 					break;
 				case '保育部':
 					v1.number = e ;
 					break;
 				case '伙食部':
 					v1.number = f ;
 					break;
 				// case '教务部':
 				// 	v1.number = g ;
 				// 	break;
 			}
 		})
 	})
	
 }
 
 function tec(){
	$.each(arrTeacher,function(i,v){
		$.each(json,function(i1,v1){
			if(v1.dept == '教务部'){
				v1.number = arrTeacher.length;
			}
			
			if(v.post == '部长' && v1.dept == '教务部'){
				v1.minister = v.name;
			}else if(v.post == '副部长' && v1.dept == '教务部'){
				v1.Vice = v.name;
			}
		})
	})
 }
	// /* 数据加载部分 */
	
	
	
	// 全选，反选
	$(".table tr>th:first-child input[type='checkbox']").on('click',function(){
		
		if($(this).is(':checked') ){
			$(".table tr>td:first-child input[type='checkbox']").each(function(){
				$(this).prop("checked",true);
			})
		}else {
			$(".table tr>td:first-child input[type='checkbox']").each(function(){
				$(this).prop("checked",false);
			})
		}
	});
	
	chooseAll.on('click',function(){

		if($(".table tr>th:first-child input[type='checkbox']").is(':checked') ){
			$(" input[type='checkbox']").each(function(){
					$(this).prop("checked",false);
				})
		}else {
			$(" input[type='checkbox']").each(function(){
				$(this).prop("checked",true);
			})
		}
	})
	
	inverseAll.on('click',function(){
		$(" input[type='checkbox']").each(function () {
		   $(this).prop("checked", !$(this).is(':checked'));
		 });

	});
	// 全选，反选
	/* 添加部门弹框 */
	$('#myModal').on('hidden.bs.modal', function (e) {
	  $('.new-dept-detail input').val('');
		$('.new-dept-detail input').next().text('');
	});
	
	$('#myModal').on('show.bs.modal', function (e) {
	  $('.new-dept-detail input').next().text('');
	});
	$('#myModal5').on('hidden.bs.modal', function (e) {
		$('.input-group input').next().text('');
	});
	
	$('#myModal5').on('show.bs.modal', function (e) {
	  $('.modify-list input').next().text('');
	});
	$('#myModal2').on('hidden.bs.modal', function (e) {
		$('.modify-list input').next().text('');
	});
	
	$('#myModal2').on('show.bs.modal', function (e) {
	  $('.input-group input').next().text('');
	});
	
	
	
	
	
	
	
	function verify(ipt,reg,str,n,tf){ 
		var res;
		var arr = [];
		
		for(var i=0;i<$('.table tr>td:nth-child('+n+')').length;i++){
			if(tf){
				ipt.val() == $('.table tr>td:nth-child('+n+')').eq(i).text();
				i++;
			}
			arr.push($('.table tr>td:nth-child('+n+')').eq(i).text())
		}
		ipt.focusout(res = function(){
			if(!reg.test(ipt.val())){
				ipt.next().text(str);
				return  false;
			}else if(arr.indexOf(ipt.val())!=-1){
				ipt.next().text('命名冲突');
				return  false;
			}
			else {
				ipt.next().text('');
				return true;
			}
		});
		return res();
	};
	
	verify(addDeptName,/^[\u4e00-\u9fa5]{2,5}$/,'部门名只能为2-5个中文',3,false);
	verify(addDeptNo,/^\d{1,8}$/,'部门编号只能为1-9个数字',4,false);
	verify(addDeptTel,/^1\d{10}$/,'部门电话只能为1开头的11位个数字',7,false);
	verify(addDeptAdr,/^[a-z]\d{3}$/,'办公室只能为a-z开头的3位个数字',6,false);
	
	verify(mdfDeptName,/^[\u4e00-\u9fa5]{2,5}$/,'部门名只能为2-5个中文',3,1);
	verify(mdfDeptNo,/^\d{1,8}$/,'部门编号只能为1-9个数字',4,1);
	verify(mdfDeptTel,/^1\d{10}$/,'部门电话只能为1开头的11位个数字',7,1);
	verify(mdfDeptAdr,/^[a-z]\d{3}$/,'办公室只能为a-z开头的3位个数字',6,1);
	verify(mdfDeptMins,/^[\u4e00-\u9fa5]{2,5}$/,'部门名只能为2-5个中文',8,1);
	verify(mdfDeptVice,/^[\u4e00-\u9fa5]{2,5}$/,'部门名只能为2-5个中文',9,1);
	
	
	verify(addYgName,/^[\u4e00-\u9fa5]{2,5}$/,'名字只能为2-5个中文',0,0);
	verify(addYgTel,/^1\d{10}$/,'部门电话只能为1开头的11位个数字',0,0);
	verify(addYgDept,/^[\u4e00-\u9fa5]{2,5}$/,'部门名只能为2-5个中文',0,0);
	verify(addYgAge,ageReg,'年龄只能为1-120',0,0);
	verify(addYgPos,/^[\u4e00-\u9fa5]{2,5}$/,'职务只能是2-5位汉字',0,0);
	
	//添加部门
	addDeptBtn.on('click',function(){
		var flag1 = verify(addDeptName,/^[\u4e00-\u9fa5]{2,5}$/,'部门名只能为2-5个中文',3,false);
		var flag2 = verify(addDeptNo,/^\d{1,8}$/,'部门编号只能为1-9个数字',4,false);
		var flag3 = verify(addDeptTel,/^1\d{10}$/,'部门电话只能为1开头的11位个数字',7,false);
		var flag4 = verify(addDeptAdr,/^[a-z]\d{3}$/,'办公室只能为a-z开头的3位个数字',6,false);
		if(flag1&&flag2&&flag3&&flag4){
			json.push({
				deptNo:parseInt(addDeptNo.val()),
				dept:addDeptName.val(),
				office:addDeptAdr.val(),
				tel:parseInt(addDeptTel.val())
			});
			render();
			alert('添加成功！');
		}
	});
	
	/* 添加部门弹框 */
	
	/* 信息修改弹窗 */
	var thisTr;
	var ygThat;
	oTable.on('click','.modify',function(){
		$('.modify-list input').next().text('');
		ygThat = $(this);
		thisTr = $(this).parents('tr').index();
		//输入框
		var indexP = paging(firLoadPage);
		$.each(info,function (index,element) {
			info[index].value = indexP[thisTr][info[index].name];
		});	
		ygXX();
		tec();
	});
	
	function ygXX(){
		//成员信息
		$('.employee-info').html('')
		$.each(arrYg,function(i,v){
				if(v.dept == $('tbody tr:eq('+thisTr+') td:nth-child(3)').text()){
					$('<li class="caozuo">'
					+'<h5>'+v.name+'<i class="fa fa-info-circle yg-info" aria-hidden="true" data-toggle="modal" data-target="#myModal4"></i>'
					+'<i class="fa fa-times-circle yg-delete" aria-hidden="true"></i></h5>'
					+'</li>').appendTo($('.employee-info'))
				}
		})
		
		$.each(arrTeacher,function(i,v){
				if(v.dept == $('tbody tr:eq('+thisTr+') td:nth-child(3)').text()){
					$('<li class="caozuo">'
					+'<h5>'+v.name+'<i class="fa fa-info-circle yg-info" aria-hidden="true" data-toggle="modal" data-target="#myModal4"></i>'
					+'<i class="fa fa-times-circle yg-delete" aria-hidden="true"></i></h5>'
					+'</li>').appendTo($('.employee-info'))
				}
		})
		
	}
	
	$('.modify-list').on('click','i',function(){
			$(this).next().removeAttr('disabled').removeAttr('placeholder');
			$(this).next().focus();
			var valueIpt = $(this).next().val();
			var indexI = $(this).parents().index()
			info.on('focusout',function(){
					json[thisTr][info[indexI].name] = $(this).val();
					//render();
			});
		});
		
	$('.info-modify').on('click',function(){
		var flag1 = verify(mdfDeptName,/^[\u4e00-\u9fa5]{2,5}$/,'部门名只能为2-5个中文',3,1);
		var flag2 = verify(mdfDeptNo,/^\d{1,8}$/,'部门编号只能为1-9个数字',4,1);
		var flag3 = verify(mdfDeptTel,/^1\d{10}$/,'部门电话只能为1开头的11位个数字',7,1);
		var flag4 = verify(mdfDeptMins,/^[\u4e00-\u9fa5]{2,5}$/,'部门名只能为2-5个中文',8,1);
		var flag5 = verify(mdfDeptVice,/^[\u4e00-\u9fa5]{2,5}$/,'部门名只能为2-5个中文',9,1);
		var flag6 = verify(mdfDeptAdr,/^[a-z]\d{3}$/,'办公室只能为a-z开头的3位个数字',6,1);
		if(flag1||flag2||flag3||flag4||flag5||flag6){
			render();
		}
	});
	
	//成员详细信息
	var detailYg = $('.yg-list li input')
	$('.employee-info').on('click','.yg-info',function(){
		var that = $(this);
		$.each(arrYg,function (index,element) {
			if(element.name == that.parents('h5').text()){
				detailYg[0].value = element.name;
				detailYg[1].value = element.dept;
				detailYg[2].value = element.position;
				detailYg[3].value = element.tel;
				detailYg[4].value = element.age;
			}
		
		})
		
		$.each(arrTeacher,function (index,element) {
			if(element.name == that.parents('h5').text()){
				detailYg[0].value = element.name;
				detailYg[1].value = element.dept;
				detailYg[2].value = element.post;
				detailYg[3].value = element.tel;
				detailYg[4].value = element.age;
			}
		
		})
		
	});
	
	$('.employee-info').on('click','.yg-delete',function(){
		var that = $(this);
		
		$.each(arrYg, function (index,element) {
			if(element.name == that.parents('h5').text()){
				arrYg.splice(index,1);
				render();
				return false;
			}
		})
		
		$.each(arrTeacher, function (index,element) {
			if(element.name == that.parents('h5').text()){
				arrTeacher.splice(index,1);
				render();
				return false;
			}
		})
		
		if(confirm('确认删除?')){
			$(this).parents('.caozuo').html('')
		}
	});
	
	//添加成员按钮
	var addYgipt = $('.yg-add-list li input')
	$('.yg-add').on('click',function(){	 
			var ygDept = ygThat.parents('tr').children().eq(2).text();
			addYgipt[1].value = ygDept;	
			
	})
	
	$('.yg-add-qr').on('click',function(){
		var flag1 = verify(addYgName,/^[\u4e00-\u9fa5]{2,5}$/,'名字只能为2-5个中文',0,0);
		var flag2 = verify(addYgTel,/^1\d{10}$/,'部门电话只能为1开头的11位个数字',0,0);
		var flag3 = verify(addYgDept,/^[\u4e00-\u9fa5]{2,5}$/,'部门名只能为2-5个中文',0,0);
		var	flag4 = verify(addYgAge,ageReg,'年龄只能为1-120',0,0);
		var flag5 = verify(addYgPos,/^[\u4e00-\u9fa5]{2,5}$/,'职务只能是2-5位汉字',0,0);
		if(flag1&&flag2&&flag3&&flag4&&flag5){
			arrYg.push({
						 name:addYgName.val(),
						 dept:addYgDept.val(),
						 position:addYgPos.val(),
						 tel:parseInt(addYgTel.val()),
						 age:parseInt(addYgAge.val())
			});
			alert('添加成功！')
			ygXX();
			tec();
			render();
		}
	});
	
	/* 删除部门 */
	var deleteRow ;
	oTable.on('click','.delete',function(){
		deleteRow = $(this)
		var pre = $(this).parents('tr').children(':nth-child(2)').text();
		json.splice(pre-1,1);
	});
	
	$('.delete-onerow').on('click',function(){
		render();
	})
	/* 多选删除 */

	deleteAllBtn.on('click',function(){
		var checkL = $(" input[class='checkBtn']");
		for(var i=checkL.length-1;i>=0;i--){
			if(checkL[i].checked == true){
				json.splice(i,1);
			}
		}
			
		$('.delete-onerow').on('click',function(){
			render();
		});
	});
	/* 多选删除 */
	
	
	/* 分页 */
	
	function showPage(){
		var pageCount = Math.ceil(json.length/5);
		$('.pagination-list').html('')
		for(var i=1;i<=pageCount;i++){
			$('<li class="pageNo"><a href="#" >'+i+'</a></li>').appendTo($('.pagination-list'));
			if(i==1){
				$('.pageNo').eq(0).addClass('active')
			}
		}	
	};
	
	showPage()
	
	
	
	function paging (n) {
		return json.slice((n-1)*5,5*n)
	}
	
	// oNext.on('click',function(){
	// 	var iP = parseInt($('.pageFirst').prev().text());
	// 	if(firLoadPage<iP){
	// 		firLoadPage++;
	// 	}
	// 	render();
	// });
	
	// oPre.on('click',function(){
	// 	var iP = parseInt($('.pageLast').next().text());
	// 	if(firLoadPage>iP){
	// 		firLoadPage--;
	// 	}
	// 	render();
	// });
	
	$('.pagination-list').on('click','.pageNo',function(){
		firLoadPage = parseInt($(this).text());
		$(this).addClass('active').siblings('li').removeClass('active');	
		render()
	});
	
	/* 搜索功能 */
	searchIpt.on('click',function(){
		var ipt = $('.search-inpt input').val();
	
		$.each(json,function(i,v){
			//console.log(i,v)
			if(ipt == v.dept){
				var n = v;
				json.splice(i,1);
				json.unshift(n);
			}
		})
		render();
	});

	
	
	
	
})//结束位置

